home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_11 / phillip2 / display.c < prev    next >
C/C++ Source or Header  |  1993-06-04  |  18KB  |  624 lines

  1.  
  2.  
  3.    /**************************************************
  4.    *
  5.    *   file d:\cips\display.c
  6.    *
  7.    *   Functions: This file contains
  8.    *      display_image
  9.    *      display_image_portion
  10.    *      display_menu_for_display_image
  11.    *      map_16_shades_of_gray
  12.    *      my_map_64_shades_of_gray
  13.    *      transform_the_colors
  14.    *
  15.    *   Purpose:
  16.    *      These functions display images on a the
  17.    *      monitor.
  18.    *
  19.    *      NOTE: This file is full of Microsoft
  20.    *            specific code.  The PC C compiler
  21.    *            makers all have their own routines
  22.    *            for making dots appear on the
  23.    *            screen.  I put the statement
  24.    *            MSC 6.0 next to these calls.
  25.    *
  26.    *
  27.    *   External Calls:
  28.    *      rtiff.c - read_tiff_image
  29.    *      cips.c - my_clear_text_screen
  30.    *      hist.c - zero_histogram
  31.    *               calculate_histogram
  32.    *               perform_histogram_equalization
  33.    *               display_histogram
  34.    *
  35.    *   Modifications:
  36.    *      17 June 1987 - created
  37.    *      August 1990 - extension modifications for use
  38.    *          in the C Image Processing System.
  39.    *
  40.    ***************************************************/
  41.  
  42.  
  43. #include "cips.h"
  44.  
  45.  
  46.  
  47.  
  48.  
  49.    /***************************
  50.    *
  51.    *   display_image(...
  52.    *
  53.    ****************************/
  54.  
  55.  
  56. display_image(file_name, image, il, ie, ll, le,
  57.               image_header, monitor_type, 
  58.               color_transform, invert, image_colors, 
  59.               display_colors, show_hist, title)
  60.    char    color_transform[],
  61.            file_name[],
  62.            monitor_type[],
  63.            title[];
  64.    int     display_colors,
  65.            image_colors,
  66.            invert,
  67.            il,
  68.            ie,
  69.            ll,
  70.            le,
  71.            show_hist;
  72.    short   image[ROWS][COLS];
  73.    struct  tiff_header_struct *image_header;
  74. {
  75.    char  channels[80],
  76.          response[80];
  77.  
  78.    int   a,
  79.          b,
  80.          c,
  81.          channel,
  82.          count,
  83.          display_mode,
  84.          dx_offset,
  85.          dy_offset,
  86.          key,
  87.          horizontal,
  88.          len,
  89.          max_horizontal,
  90.          max_vertical,
  91.          not_finished,
  92.          q,
  93.          r,
  94.          vertical,
  95.          x_offset,
  96.          y_offset;
  97.  
  98.    unsigned int block,
  99.                 color,
  100.                 i,
  101.                 j,
  102.                 x,
  103.                 y;
  104.    unsigned long histogram[256], new_hist[256];
  105.  
  106.  
  107.      /**********************************************
  108.      *
  109.      *   If you want to display the histogram and 
  110.      *   do not want to perform hist equalization, 
  111.      *   then zero the histogram for calculations.
  112.      *
  113.      **********************************************/
  114.  
  115.    if(  (show_hist == 1)   &&
  116.         (color_transform[0] != 'H'))
  117.       zero_histogram(histogram);
  118.  
  119.    not_finished = 1;
  120.    while(not_finished){
  121.  
  122.  
  123.       if(display_colors == 16){
  124.          if(monitor_type[0] == 'V'){
  125.             horizontal   = 4;
  126.         vertical = 6;
  127.         display_mode = VRES16COLOR; /* MSC 6.0 */
  128.          }  /* ends if V */
  129.          if(monitor_type[0] == 'E'){
  130.             horizontal   = 3;
  131.             vertical     = 6;
  132.             display_mode = ERESCOLOR; /* MSC 6.0 */
  133.          }  /* ends if E */
  134.  
  135.       }  /* ends if colors == 16 */
  136.  
  137.       else{
  138.          horizontal   = 2;
  139.          vertical     = 2;
  140.          display_mode = MAXCOLORMODE; /* MSC 6.0 */
  141.       }
  142.  
  143.         /********************************************
  144.         *
  145.         *   Somehow, my dx and dy offsets are 
  146.         *   backwards from my horizontal and vertical 
  147.         *   variables. Trying to center the images 
  148.         *   on the screen. March 21 1992
  149.         *
  150.         ********************************************/
  151.  
  152.       max_horizontal = (image_header->image_length+50)
  153.                        /COLS;
  154.       max_vertical   = (image_header->image_width+50)
  155.                        /ROWS;
  156.  
  157.       dy_offset = ((horizontal-max_horizontal)/2)
  158.                   *COLS + 50;
  159.       dx_offset = ((vertical-max_vertical)/2)
  160.                   *ROWS + 20;
  161.  
  162.       if(max_horizontal > horizontal) dy_offset = 0;
  163.       if(max_vertical > vertical)     dx_offset = 0;
  164.  
  165.       if(horizontal > max_horizontal) 
  166.          horizontal = max_horizontal;
  167.       if(vertical > max_vertical)     
  168.          vertical   = max_vertical;
  169.  
  170.  
  171.         /****************************************
  172.         *
  173.         *   If color transform wants histogram
  174.         *   equalization, then read in the
  175.         *   image arrays and calculate the
  176.         *   histogram.   Zero both the histogram
  177.         *   and the new_hist.  You will need the
  178.         *   new_hist if you want to display the
  179.         *   equalized hist.
  180.         *
  181.         *****************************************/
  182.  
  183.       if(color_transform[0] == 'H'){
  184.          count = 1;
  185.          zero_histogram(histogram);
  186.          zero_histogram(new_hist);
  187.          for(a=0; a<vertical; a++){
  188.             for(b=0; b<horizontal; b++){
  189.  
  190.                x = a*COLS;
  191.                y = b*ROWS;
  192.  
  193.                printf(
  194.                   "\nDISPLAY> Calculating histogram");
  195.                printf(" %d of %d",
  196.                   count,vertical*horizontal);
  197.                count++;
  198.                read_tiff_image(file_name, image, il+y,
  199.                             ie+x, ll+y, le+x);
  200.                calculate_histogram(image, histogram);
  201.  
  202.             }  /* ends loop over b */
  203.          }  /* ends loop over a */
  204.       }  /* ends if display_mode == H */
  205.  
  206.  
  207.         /* set graphics mode */
  208.  
  209.    my_setvideomode(display_mode); /* MSC 6.0 */
  210.    if(display_colors == 16) 
  211.       map_16_shades_of_gray(display_mode);
  212.    if(display_colors == 256) 
  213.       my_map_64_shades_of_gray();
  214.  
  215.  
  216.         /****************************************
  217.         *
  218.         *   Loop over this size and
  219.         *   read and display ROWSxCOLS arrays.
  220.         *
  221.         *   If you want to show the histogram AND
  222.         *   do not want to do hist equalization
  223.         *   then calculate the hist from the
  224.         *   original image array.
  225.         *
  226.         *   If you want to do hist equalization
  227.         *   then calculate the new_hist AFTER
  228.         *   the image has been equalized by the
  229.         *   the transform_the_colors function.
  230.         *
  231.         *   NOTE: Remember that the function
  232.         *   transform_the_colors changes the
  233.         *   gray shade values in image array.
  234.         *
  235.         *****************************************/
  236.  
  237.         /*****************************************
  238.         *
  239.         *   These statements place a gray 
  240.         *   background across the display area of 
  241.         *   a VGA screen.  This reduces the 
  242.         *   contrast between the screen background 
  243.         *   and the images you display. This makes 
  244.         *   it easier to take photos.
  245.         *
  246.         *******************************************/
  247.  
  248.       /* MSC 6.0 */
  249.       my_setlinestyle(0xFFFF);
  250.       my_setcolor(10);
  251.       for(i=0; i<640;i++){
  252.          my_moveto(i, 0);
  253.          my_lineto(i, 480);
  254.       }
  255.  
  256.       for(a=0; a<vertical; a++){
  257.          for(b=0; b<horizontal; b++){
  258.  
  259.             x = a*COLS;
  260.             y = b*ROWS;
  261.             read_tiff_image(file_name, image, il+y,
  262.                             ie+x, ll+y, le+x);
  263.             if(  (show_hist == 1)  &&
  264.                  (color_transform[0] != 'H'))
  265.                calculate_histogram(image, histogram);
  266.  
  267.             transform_the_colors(image, 
  268.                                  color_transform,
  269.                                  display_colors,
  270.                                  image_colors, 
  271.                                  histogram,
  272.                                  horizontal, 
  273.                                  vertical);
  274.  
  275.             if(color_transform[0] == 'H')
  276.                calculate_histogram(image, new_hist);
  277.           display_image_portion(image, x+dx_offset,
  278.                                 y+dy_offset, 
  279.                                 display_colors,
  280.                                 imag